package com.devgroupvn.dota;

import java.util.List;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.net.Uri;

public class CheckAppInstall
{
	Context mContext;
	public static String packageNameRockPlayer = "com.redirectin.rockplayer.android.unified.lite";
//	public static String packageNamenswPlayer = "com.nsw.android.mediaexplorer";

	// List<ApplicationInfo> listApp;
	// ArrayList<String> nameInstalledApp;

	public CheckAppInstall(Context context)
	{
		mContext = context;
	}

	public boolean checkApp(Context context)
	{
		mContext = context;
		PackageManager pm = mContext.getPackageManager();
		List<ApplicationInfo> listApp = pm.getInstalledApplications(0);
		// ArrayList<String> nameInstalledApp = new ArrayList<String>();

		for (int i = 0; i < listApp.size(); i++)
		{
			ApplicationInfo appInfo = listApp.get(i);
			String packageName = appInfo.packageName;
			if (packageName.contains(packageNameRockPlayer))
			{
				return true;
			}
			// nameInstalledApp.add(packageName);
		}
		return false;
	}

	private static final String GooglePlayStorePackageNameNew = "com.redmanit.play_store";

	public void installApp(Context context)
	{

		AlertDialog.Builder builder = new AlertDialog.Builder(context);
		builder.setTitle("JoinDota").setMessage(R.string.installapp).setCancelable(true)
				.setPositiveButton(context.getString(R.string.ok), new DialogInterface.OnClickListener()
				{

					@Override
					public void onClick(DialogInterface dialog, int which)
					{
//						Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Configs.LinkInstallApp));
//						PackageManager pk = mContext.getPackageManager();
//						intent = pk.getLaunchIntentForPackage(GooglePlayStorePackageNameNew);
//						mContext.startActivity(intent);
						 mContext.startActivity(new Intent(Intent.ACTION_VIEW,
						 Uri.parse(Configs.LinkInstallApp)));
					}
				}).create().show();
		// mContext.startActivity(new Intent(Intent.ACTION_VIEW,
		// Uri.parse(Configs.LinkInstallApp)));
	}

}
